#pragma once
#include <iostream>
#include <string>

using std::cout;
using std::endl;

class Task
{
public:
    Task()
    {
    }
    Task(int x, int y, char op) : _x(x), _y(y), _op(op), _res(0), _exitCode(0)
    {
    }
    // 对()进行重载 -- 仿函数
    void operator()()
    {
        switch (_op)
        {
        case '+':
            _res = _x + _y;
            break;
        case '-':
            _res = _x - _y;
            break;
        case '*':
            _res = _x * _y;
            break;
        case '/':
        {
            if (_y == 0)
                _exitCode = -1;
            else
                _res = _x / _y;
        }
        break;
        case '%':
        {
            if (_y == 0)
                _exitCode = -1;
            else
                _res = _x % _y;
        }
        break;
        default:
            break;
        }
    }

    std::string formatExpression()
    {
        return std::to_string(_x) + _op + std::to_string(_y) + "=";
    }

    std::string formatResult()
    {
        return std::to_string(_res) + " (" + std::to_string(_exitCode) + ")";
    }

    ~Task()
    {
    }

private:
    int _x;
    int _y;
    char _op;

    int _res;      // 结果
    int _exitCode; // 退出码
};